import java.awt.*;
import java.util.*;
import java.util.List;

public class Test {

	public static void main(String[] args) {
		/*ListNode l1 = new ListNode(1);
		ListNode l2 = new ListNode(2);
		ListNode l3 = new ListNode(3);
		l1.next = l2;
		l2.next = l3;
		removeNthFromEnd(l1,2);*/
		Queue<Integer> qu = new LinkedList<>();
		qu.offer(1);
		qu.add(2);
		System.out.println(qu.element());
		for (Integer integer : qu) {
			System.out.println(integer);
		}


	}


	//合并两个有序的链表
	/*
	 * public ListNode mergeTwoLists(ListNode list1, ListNode list2) { if (list1 ==
	 * null || list2 == null)return null; if (list1==null && list2!=null)return
	 * list2; if (list2== null&& list1!=null)return list1;
	 * 
	 * ListNode newHead = new ListNode(0); newHead.next = list1; ListNode temp =
	 * newHead;
	 * 
	 * ListNode right = list2; while(temp.next!= null){ while(right!=null&&){ if ()
	 * } } }
	 */


	//删除链表的倒数第n个数据
	public ListNode removeNthFromEnd(ListNode head, int n) {
		Stack<ListNode> stack = new Stack<>();

		ListNode newHead = new ListNode(0);
		ListNode temp = newHead;
		newHead.next = head;
		while(temp!=null){
			stack.push(temp);
			temp = temp.next;
		}
		for (int i = 0; i < n; i++) {
			stack.pop();
		}
		ListNode cur = stack.peek();
		cur.next = cur.next.next;

		return newHead.next;
	}
	//计算链表长度
	public int lengthListNode(ListNode node){
		int result =0;

		while(node!= null){
			result++;
		}
		return result;
	}

	//从上到下按层打印二叉树，同一层的节点按从左到右的顺序打印，每一层打印到一行
	public List<List<Integer>> levelOrder1(TreeNode root) {
		if (root == null) return new ArrayList<>();
		Queue<TreeNode> queue = new LinkedList<>();
		queue.offer(root);
		int depth = depth(root);
		for (int i = 0; i < depth; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			for (int j = 0; j < i*i; j++) {

			}
		}
		return null;
	}
	//求二叉树的深度
	public int depth(TreeNode root){
		if (root == null)return 0;
		int left = depth(root.left);
		int right = depth(root.right);

		return left>right?(left+1):(right+1);
	}


	//层次遍历二叉树
	public int[] levelOrder(TreeNode root) {
		if (root == null)return new int[0];
		Queue<TreeNode> queue = new LinkedList<>();
		ArrayList<Integer> list = new ArrayList<>();
		queue.offer(root);

		while(!queue.isEmpty()){
			TreeNode temp = queue.poll();
			list.add(temp.val);

			if (temp.left != null){
				queue.offer(temp.left);
			}
			if (temp.right != null){
				queue.offer(temp.right);
			}
		}

		int[] result = new int[list.size()];
		for (int i = 0; i < list.size(); i++) {
			result[i] = list.get(i);
		}

		return result;

	}
	class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode(int x) { val = x; }
  }
	//链表反转
	public ListNode reverseList(ListNode head) {
		ListNode temp = head;
		ListNode cur;
		ListNode newHead = new ListNode(0);

		while(temp!=null){
			cur = temp.next;
			temp.next = newHead.next;
			newHead.next = temp;
			temp = cur;
		}
		return newHead.next;
	}

	//原地删除重复元素
	public static int removeDuplicates(int[] nums) {
		int size = nums.length;
		Map<Integer, Integer> map = new LinkedHashMap<>();
		for (int i = 0; i < size; i++) {
			if (!map.containsKey(nums[i])){
				map.put(nums[i],1);
			}else {
				map.put(nums[i],map.get(nums[i])+1);
			}
		}

		int n = 0;
		for (int i = 0; i < size; i++) {
			if (map.get(nums[i]) > 1){
				n++;
				for (int j = i; j < size-1; j++) {
					nums[j] = nums[j+1];
				}
			}
		}
		for (int i = 0; i < size; i++) {
			System.out.println(nums[i]);
		}
		return n;

	}

	public ListNode removeElements(ListNode head, int val) {
		if (head == null){
			return head;
		}

		ListNode temp = new ListNode(0);
		temp.next = head;
		while(temp.next != null){
			if (temp.val == val){
				temp.next = temp.next.next;
			}
			temp = temp.next;
		}
		return temp.next;
	}
	//合并两个递增数组
	 public static void merge(int[] nums1, int m, int[] nums2, int n) {
		 for (int i = n; i < m; i++) {
			 nums1[i] = nums2[i-n];
		 }


		 Arrays.sort(nums1);


	 }
	public boolean hasCycle(ListNode head) {
		HashSet<Integer> set = new HashSet<>();
		ListNode temp = head;
		while(temp != null){
			if (!set.add(temp.val)){
				return true;
			}
			temp  =temp.next;
		}

		return false;
	}
}
class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }}
class TreeNode {
	      int val;
	      TreeNode left;
	      TreeNode right;
	      TreeNode() {}
	      TreeNode(int val) { this.val = val; }
	     TreeNode(int val, TreeNode left, TreeNode right) {
	          this.val = val;
	         this.left = left;
	          this.right = right;
	      }
	  }